package com.wy.sx_excel.controller;

import com.wy.utils.ExcelUtils;
import com.wy.utils.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2019/9/1115:59
 */
@RestController
@RequestMapping("my")
public class MyExport {
    @RequestMapping("export")
    public void export(HttpServletResponse response){
        List<User> list = new ArrayList<User>();
        for (int i=0;i<10;i++) {
            User us = new User();
            us.setName("张三"+i);
            us.setPhone(i+"11111111111");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            us.setCreate_time(sdf.format(new Date()));
            us.setEmail(i+"wawerer@123123.com");
            list.add(us);
        }
        String columnNames[] = {"姓名","电话","时间","邮箱"};
        String columns[] = {"name","phone","create_time","email"};
        ExcelUtils.exportExcel(response,list,columnNames,columns,"123","斯蒂芬斯蒂芬");
    }
}
